export type TypedKey<T> = {
  key: string;
  defaultValue: T;
};

export interface Share {
  [key: string]: unknown;
}

export type Middleware = (
  key: string,
  value: unknown,
  next: (value: unknown) => void,
) => void;

export function createTypedKey<T>(key: string, defaultValue: T): TypedKey<T> {
  return { key, defaultValue };
}

export function isTypedKey<T>(key: unknown): key is TypedKey<T> {
  return (key !== null &&
    typeof key === 'object' &&
    'key' in key &&
    'defaultValue' in key) as boolean;
}
